package com.credit.jumu.playcard.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.credit.jumu.playcard.R;
import com.credit.jumu.playcard.bean.CardInfo;
import com.credit.jumu.playcard.bean.HomeInfo;
import com.credit.jumu.playcard.utils.GlideUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/18/018.
 */

public class CardListAdapter extends BaseAdapter {
	private Context context;
	private List<CardInfo> mlistInfo = new ArrayList<CardInfo>();

	public CardListAdapter(List<CardInfo> mlistInfo, Context context) {
		this.context = context;
		this.mlistInfo = mlistInfo;

	}

	@Override
	public int getCount() {
		return mlistInfo.size();
	}

	@Override
	public Object getItem(int position) {
		return mlistInfo.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (null == viewHolder) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_card, null);
			viewHolder = new ViewHolder();
			viewHolder.title = (TextView) convertView.findViewById(R.id.cardname);
			viewHolder.text = (TextView) convertView.findViewById(R.id.cardnum);
			viewHolder.image = convertView.findViewById(R.id.caredicon);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		GlideUtil.loadImage(context, mlistInfo.get(position).getCardIcon(), viewHolder.image);
		viewHolder.title.setText(mlistInfo.get(position).getCardNume());
		viewHolder.text.setText(mlistInfo.get(position).getCardNum());

		return convertView;
	}

	private class ViewHolder {
		private TextView title;
		private TextView text;
		private ImageView image;
	}
}

